from __future__ import annotations

from dataclasses import dataclass


@dataclass
class ConcreteMix:
    water_kg_m3: float
    cement_kg_m3: float
    sand_kg_m3: float
    gravel_kg_m3: float
    w_c_ratio: float
    note: str


def design_mix_by_strength(target_cu_MPa: float, slump_mm: int = 100, max_agg_mm: int = 20, density_fresh_concrete_kg_m3: float = 2400.0) -> ConcreteMix:
    """混凝土配合比简化设计（经验近似）。

    - 经验水灰比：w/c ≈ 0.55 - 0.01*(f_cu - 30)/5
    - 用水量：依据坍落度与最大粒径：W ≈ 185 + k_slump
    - 胶凝材料：C = W/(w/c)
    - 砂率：S% ≈ 36±3 （随坍落度、粒径调整）
    - 骨料质量按目标湿密度平衡
    """

    # 经验公式
    wc = max(0.35, min(0.65, 0.55 - 0.01 * max(0.0, (target_cu_MPa - 30.0) / 5.0)))
    water = 185.0 + (slump_mm - 50) * 0.3 - (max_agg_mm - 20) * 1.5
    water = max(150.0, min(210.0, water))
    cement = water / wc
    sand_ratio = 0.36 + (100 - slump_mm) * 0.0005 + (20 - max_agg_mm) * 0.002
    sand_ratio = max(0.32, min(0.42, sand_ratio))
    solids = density_fresh_concrete_kg_m3 - water - cement
    sand = solids * sand_ratio
    gravel = solids - sand
    return ConcreteMix(water_kg_m3=water, cement_kg_m3=cement, sand_kg_m3=sand, gravel_kg_m3=gravel, w_c_ratio=wc, note="经验配比，需试拌修正")


